package br.com.sysreserva.dao;

import java.util.List;

import org.hibernate.Session;

import br.com.sysreserva.entity.Sala;
import br.com.sysreserva.util.HibernateUtil;



public class SalaDao {
	public Sala getSala(Long id){
		
		Session s = HibernateUtil.getSessionFactory().openSession();
		return (Sala) s.load(Sala.class, id);
		
	}

	public void save(Sala sala){
		Session s = HibernateUtil.getSessionFactory().openSession();
		s.beginTransaction();
		s.save(sala);
		s.beginTransaction().commit();
	}
	
	public void delete(Sala sala){
		
		Session s = HibernateUtil.getSessionFactory().openSession();
		s.beginTransaction();
		s.delete(sala);
		s.beginTransaction().commit();
	}
	
	public void update(Sala sala){
		
		Session s = HibernateUtil.getSessionFactory().openSession();
		s.beginTransaction();
		s.update(sala);
		s.beginTransaction().commit();
	}
	
	public List<Sala> listAll(){
		Session s = HibernateUtil.getSessionFactory().openSession();
		s.beginTransaction();
		List lista = s.createQuery("select s From Sala s").list();
		s.beginTransaction().commit();
		return lista;
		
		
	}

}
